/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.spreedairy.portal.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.spreedairy.portal.model.CustomFieldValue;
import com.spreedairy.portal.model.CustomFieldValueModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the CustomFieldValue service. Represents a row in the &quot;spreedairy_CustomFieldValue&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.spreedairy.portal.model.CustomFieldValueModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link CustomFieldValueImpl}.
 * </p>
 *
 * @author SpreeDairy
 * @see CustomFieldValueImpl
 * @see com.spreedairy.portal.model.CustomFieldValue
 * @see com.spreedairy.portal.model.CustomFieldValueModel
 * @generated
 */
public class CustomFieldValueModelImpl extends BaseModelImpl<CustomFieldValue>
	implements CustomFieldValueModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a custom field value model instance should use the {@link com.spreedairy.portal.model.CustomFieldValue} interface instead.
	 */
	public static final String TABLE_NAME = "spreedairy_CustomFieldValue";
	public static final Object[][] TABLE_COLUMNS = {
			{ "recId", Types.BIGINT },
			{ "itemId", Types.BIGINT },
			{ "keyName", Types.VARCHAR },
			{ "keyValue", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table spreedairy_CustomFieldValue (recId LONG not null primary key,itemId LONG,keyName VARCHAR(75) null,keyValue VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table spreedairy_CustomFieldValue";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.spreedairy.portal.model.CustomFieldValue"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.spreedairy.portal.model.CustomFieldValue"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.spreedairy.portal.model.CustomFieldValue"),
			true);
	public static long ITEMID_COLUMN_BITMASK = 1L;
	public static long KEYNAME_COLUMN_BITMASK = 2L;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.spreedairy.portal.model.CustomFieldValue"));

	public CustomFieldValueModelImpl() {
	}

	public long getPrimaryKey() {
		return _recId;
	}

	public void setPrimaryKey(long primaryKey) {
		setRecId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_recId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return CustomFieldValue.class;
	}

	public String getModelClassName() {
		return CustomFieldValue.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("recId", getRecId());
		attributes.put("itemId", getItemId());
		attributes.put("keyName", getKeyName());
		attributes.put("keyValue", getKeyValue());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long recId = (Long)attributes.get("recId");

		if (recId != null) {
			setRecId(recId);
		}

		Long itemId = (Long)attributes.get("itemId");

		if (itemId != null) {
			setItemId(itemId);
		}

		String keyName = (String)attributes.get("keyName");

		if (keyName != null) {
			setKeyName(keyName);
		}

		String keyValue = (String)attributes.get("keyValue");

		if (keyValue != null) {
			setKeyValue(keyValue);
		}
	}

	public long getRecId() {
		return _recId;
	}

	public void setRecId(long recId) {
		_recId = recId;
	}

	public long getItemId() {
		return _itemId;
	}

	public void setItemId(long itemId) {
		_columnBitmask |= ITEMID_COLUMN_BITMASK;

		if (!_setOriginalItemId) {
			_setOriginalItemId = true;

			_originalItemId = _itemId;
		}

		_itemId = itemId;
	}

	public long getOriginalItemId() {
		return _originalItemId;
	}

	public String getKeyName() {
		if (_keyName == null) {
			return StringPool.BLANK;
		}
		else {
			return _keyName;
		}
	}

	public void setKeyName(String keyName) {
		_columnBitmask |= KEYNAME_COLUMN_BITMASK;

		if (_originalKeyName == null) {
			_originalKeyName = _keyName;
		}

		_keyName = keyName;
	}

	public String getOriginalKeyName() {
		return GetterUtil.getString(_originalKeyName);
	}

	public String getKeyValue() {
		if (_keyValue == null) {
			return StringPool.BLANK;
		}
		else {
			return _keyValue;
		}
	}

	public void setKeyValue(String keyValue) {
		_keyValue = keyValue;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			CustomFieldValue.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public CustomFieldValue toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (CustomFieldValue)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		CustomFieldValueImpl customFieldValueImpl = new CustomFieldValueImpl();

		customFieldValueImpl.setRecId(getRecId());
		customFieldValueImpl.setItemId(getItemId());
		customFieldValueImpl.setKeyName(getKeyName());
		customFieldValueImpl.setKeyValue(getKeyValue());

		customFieldValueImpl.resetOriginalValues();

		return customFieldValueImpl;
	}

	public int compareTo(CustomFieldValue customFieldValue) {
		long primaryKey = customFieldValue.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		CustomFieldValue customFieldValue = null;

		try {
			customFieldValue = (CustomFieldValue)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = customFieldValue.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		CustomFieldValueModelImpl customFieldValueModelImpl = this;

		customFieldValueModelImpl._originalItemId = customFieldValueModelImpl._itemId;

		customFieldValueModelImpl._setOriginalItemId = false;

		customFieldValueModelImpl._originalKeyName = customFieldValueModelImpl._keyName;

		customFieldValueModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<CustomFieldValue> toCacheModel() {
		CustomFieldValueCacheModel customFieldValueCacheModel = new CustomFieldValueCacheModel();

		customFieldValueCacheModel.recId = getRecId();

		customFieldValueCacheModel.itemId = getItemId();

		customFieldValueCacheModel.keyName = getKeyName();

		String keyName = customFieldValueCacheModel.keyName;

		if ((keyName != null) && (keyName.length() == 0)) {
			customFieldValueCacheModel.keyName = null;
		}

		customFieldValueCacheModel.keyValue = getKeyValue();

		String keyValue = customFieldValueCacheModel.keyValue;

		if ((keyValue != null) && (keyValue.length() == 0)) {
			customFieldValueCacheModel.keyValue = null;
		}

		return customFieldValueCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(9);

		sb.append("{recId=");
		sb.append(getRecId());
		sb.append(", itemId=");
		sb.append(getItemId());
		sb.append(", keyName=");
		sb.append(getKeyName());
		sb.append(", keyValue=");
		sb.append(getKeyValue());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(16);

		sb.append("<model><model-name>");
		sb.append("com.spreedairy.portal.model.CustomFieldValue");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>recId</column-name><column-value><![CDATA[");
		sb.append(getRecId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>itemId</column-name><column-value><![CDATA[");
		sb.append(getItemId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyName</column-name><column-value><![CDATA[");
		sb.append(getKeyName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyValue</column-name><column-value><![CDATA[");
		sb.append(getKeyValue());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = CustomFieldValue.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			CustomFieldValue.class
		};
	private long _recId;
	private long _itemId;
	private long _originalItemId;
	private boolean _setOriginalItemId;
	private String _keyName;
	private String _originalKeyName;
	private String _keyValue;
	private long _columnBitmask;
	private CustomFieldValue _escapedModelProxy;
}